package com.joesem.sale.client.logic.notice

import android.app.Application
import com.joesem.sale.client.base.BaseViewModel
import com.joesem.sale.client.base.request
import com.joesem.sale.client.base.toast
import com.joesem.sale.client.network.data.NoticeListMode

const val NOTICE_TYPE_ORDER = "work_order"
const val NOTICE_TYPE_EVENT = "event"
class NoticeViewModel(application: Application) : BaseViewModel(application) {

    fun getNoticeList(isFirst: Boolean, type: String) {
        request(request = {
            noticeList(isFirst, type)
        }, response = {
            actionIntent(NoticeListIntent(isFirst, it.data?.filterNotNull() ?: arrayListOf()))
        }, responseFailed = {
            toast(it.message)
            actionIntent(NoticeListIntent(isFirst, arrayListOf()))
        })
    }

    fun noticeRead(id: Int?) {
        request(request = {
            noticeRead(id)
        }, response = {}, responseFailed = {})
    }

    class NoticeListIntent(val isFirst: Boolean, val data: List<NoticeListMode>)
}